function backDeviceGroup() {
	window.location.href = 'deviceGroupAdd.jsp';

}
//			全体打钩
function checkInput() {
	var tick = $(".tick").css("display");
	if(tick == "none") {
		$(".tick").show();
		tickId = sessionStorage.getItem("GroupAll");
	} else if(tick == "block") {
		$(".tick").hide();
		$(".tick_block ").hide();
	}
}
//			单独打钩
var tickId = 0;
var tickaId = '';
var somearray = []

function removeByValue(arr, val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == val) {
			arr.splice(i, 1);
			break;
		}
	}
}

function checkInputA(data) {
	var ticka = "tick_" + data.id
	var tickBlock = document.getElementById(ticka);
	if(tickBlock.style.display == "block") {
		tickBlock.style.display = "none";
		removeByValue(somearray, data.id);
		tickId = tickId - 1;
		tickaId = somearray[0];
	} else if(tickBlock.style.display == "" || tickBlock.style.display == "none") {
		tickBlock.style.display = "block";
		removeByValue(somearray, data.id);
		somearray.push(data.id);
		tickaId = somearray[0];
		tickId = tickId + 1;
	}
}

var param = {
	companyId: $.Cookie("companyId"),
	userId: $.Cookie("userId"),
	session: $.Cookie("session")
}
$.ajax({
	url: 'dvcGroupList',
	type: 'POST',
	data: param,
	dataType: 'json',
	success: function(data) {
		if(data.errorCode == 0) {
			sessionStorage.setItem("GroupAll", data.result.length);
			$.each(data.result, function(i, value) {
				if(i % 2 == 0) {
				var error_tpl = '<div class="deviceGroup_content_contenta"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.dvcGroupId + '"><div id="tick_' + value.dvcGroupId + '" class="tick">√</div></div><div class="manage_content_header_div">' + value.dvcGroupId + '</div><div class="manage_content_header_div">' + value.dvcGroupName + '</div><div class="manage_content_header_div">' + value.remark + '</div><div class="manage_content_header_div">' + value.lastModifyUser + '</div><div class="manage_content_header_div">' + value.lastModifyTime + '</div></div>'
					
				}else{
				var error_tpl = '<div class="deviceGroup_content_content"><div onclick="checkInputA(this)" class="content_input_b" id="' + value.dvcGroupId + '"><div id="tick_' + value.dvcGroupId + '" class="tick">√</div></div><div class="manage_content_header_div">' + value.dvcGroupId + '</div><div class="manage_content_header_div">' + value.dvcGroupName + '</div><div class="manage_content_header_div">' + value.remark + '</div><div class="manage_content_header_div">' + value.lastModifyUser + '</div><div class="manage_content_header_div">' + value.lastModifyTime + '</div></div>'
					
				}

				$("#pageTool").append(error_tpl);

			});
		} else if(data.errorCode == -6) {
			alert("登录超时！")
			top.location.href = 'index.jsp';
		}

	},
	error: function(err) {
		alert("连接服务器失败！请重新提交！")
		top.location.href = 'index.jsp';
	}
});

function editorDeviceGroup() {
	if(tickId == 0) {
		alert("请选择你要编辑的记录！")
	} else if(tickId == 1) {
		sessionStorage.setItem("tickId", tickId);
		sessionStorage.setItem("tickaId", tickaId);
		window.location.href = 'deviceGroupAmend.jsp';

	} else if(tickId > 1) {
		alert("一次只能编辑一条记录！")
	}
}

function deleteGroup() {
	if(tickId == 0) {
		alert("请选择你要删除的记录！")
	} else if(tickId == 1) {
		var param = {
			companyId: $.Cookie("companyId"),
			userId: $.Cookie("userId"),
			session: $.Cookie("session"),
			operationFlag: 2,
			dvcGroupId: tickaId,
		}
		$.ajax({
			url: 'dvcGroupOperation',
			type: 'POST',
			data: param,
			dataType: 'json',
			success: function(data) {
				if(data.errorCode == '0') {
					window.location.href = 'deviceGroup.jsp';

				} else if(data.errorCode == '-1') {
					alert("系统异常！请重试")
					window.location.href = 'deviceGroup.jsp';

				} else if(data.errorCode == '-6') {
					alert("登陆超时！请重新登录")
			top.location.href = 'index.jsp';
					
				}

			},
			error: function(err) {
				alert("连接服务器失败！请重新提交！")
			top.location.href = 'index.jsp';
				
			}
		});

		tickId = 0;
	} else if(tickId > 1) {
		alert("一次只能删除一条记录！")
	}
}